#include "CText.h"
using namespace GUI;

CText::CText(const int height,const int r, const int g,const  int b) : CGUIObject(0,height)
{
  fontColor = D3DCOLOR_ARGB(255,r,g,b);
  pD3DDevice = Engine::CDevice::getInstance()->getD3DDevice();
	D3DXCreateFont(pD3DDevice,height,width,FW_BOLD,0,FALSE, DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,
	DEFAULT_PITCH | FF_DONTCARE,TEXT("Arial"),&pFont);
  text = "";

}
CText::~CText()
{
}

void CText::render()
{
  RECT rect;
  rect.left=(LONG)posX;
  rect.right=(LONG)posX;
  rect.top=(LONG)posY;
  rect.bottom=(LONG)posY;
  pFont->DrawText(NULL,text.c_str(),-1,&rect,DT_CALCRECT,fontColor);
  pFont->DrawText(NULL,text.c_str(),-1,&rect,DT_CENTER,fontColor);

}

void CText::setText(const std::string text_in)
{
  text = text_in;
}
std::string CText::getText()
{
  return text;
}
void CText::clean()
{
  if (pFont)
  {
    pFont->Release();
  }
  pFont =0;

}
void CText::onLostDevice()
{
  clean();
}

void CText::onResetDevice()
{
	D3DXCreateFont(pD3DDevice,height,width,FW_BOLD,0,FALSE, DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,
	DEFAULT_PITCH | FF_DONTCARE,TEXT("Arial"),&pFont);
}